package cn.niit.cn.niit.dynamic;

import cn.niit.proxy.IHourseRental;
import cn.niit.proxy.OwnerRental;

import java.lang.annotation.Target;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.logging.Handler;

public class MyInvocationHandler implements IHourseRental {

private IHourseRental target;

    public MyInvocationHandler(IHourseRental hourseRental) {
        this.target = hourseRental;
    }


    public Object getProxy(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("getproxy 开始代理" + method.getName());
                        System.out.println("getproxy参数" +args);
                        Object returnVal = method.invoke(target,args);
                        System.out.println(returnVal);
                        System.out.println("getproxy完成代理");
                        return returnVal;
                    }
                }

        );
    }

    public void rent() {

    }
}
